/**
 * 格式化时间
 * @param {number} time - 时间戳
 * @param {string} format - 格式化
 * @return {string} - 格式化后的时间
 */
export const formatDateTime = (time, format = "YYYY-MM-DD HH:mm:ss") => {
    if (!time) return "-";
  
    const isSecondLevel = time.toString().length === 10;
    const date = new Date(isSecondLevel ? time * 1000 : time);
  
    const map = {
      YYYY: date.getFullYear(),
      MM: ("0" + (date.getMonth() + 1)).slice(-2),
      DD: ("0" + date.getDate()).slice(-2),
      HH: ("0" + date.getHours()).slice(-2),
      mm: ("0" + date.getMinutes()).slice(-2),
      ss: ("0" + date.getSeconds()).slice(-2),
    };
  
    return format.replace(/YYYY|MM|DD|HH|mm|ss/g, (matched) => map[matched]);
  }